package logic

import (
	"context"
	"storage/models"

	"storage/internal/svc"
	"storage/pb/storage"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateFolderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateFolderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateFolderLogic {
	return &UpdateFolderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// UpdateFolder 更新文件夹
func (l *UpdateFolderLogic) UpdateFolder(in *storage.FolderInfo) (*storage.Empty, error) {
	folder := &models.Folders{Id: in.Id}
	if in.FolderName != "" {
		folder.FolderName = in.FolderName
	}
	if in.ParentId != 0 {
		folder.ParentId = in.ParentId
	}
	if in.Status != 0 {
		folder.Status = in.Status
	}
	err := l.svcCtx.FolderModel.Update(l.ctx, folder)
	if err != nil {
		return nil, err
	}
	return &storage.Empty{}, nil
}
